package com.koron.device.service.impl;

import com.koron.device.bean.EquipmentParams;
import com.koron.device.mapper.TypeParamsMapper;
import com.koron.device.service.TypeParamsService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author qingfeng
 * @description: TODO
 * @date 2021/7/12 20:29
 */
@Service
public class TypeParamsServiceImpl implements TypeParamsService {

    @Override
    @TaskAnnotation("getDefaultParams")
    public List<EquipmentParams> getDefaultParams(SessionFactory factory) {
        return factory.getMapper(TypeParamsMapper.class).getDefaultParams();
    }

    @Override
    @TaskAnnotation("getBasicParamsByTypeId")
    public List<EquipmentParams> getBasicParamsByTypeId(SessionFactory factory, String typeId) {
        List<EquipmentParams> params = factory.getMapper(TypeParamsMapper.class).getBasicParamsByTypeId(typeId);
        Collections.sort(params, Comparator.comparing(EquipmentParams::getSort));
        return params;
    }

    @Override
    @TaskAnnotation("getTechParamsByTypeId")
    public List<EquipmentParams> getTechParamsByTypeId(SessionFactory factory, String typeId) {
        List<EquipmentParams> params = factory.getMapper(TypeParamsMapper.class).getTechParamsByTypeId(typeId);
        Collections.sort(params, Comparator.comparing(EquipmentParams::getSort));
        return params;
    }

}
